import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, Events } from 'ionic-angular';
import {BtDataService} from "../bt-data.service";
import {LeagueTabsPage} from "../tabs/league-tabs";

/**
 * Generated class for the DataBkBootstrapPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage({name:'BkZlkPage'})
@Component({
  selector: 'page-data-bk-bootstrap',
  templateUrl: 'data-bk-bootstrap.html',
})
export class DataBkBootstrapPage {

      constructor(public navCtrl: NavController, public navParams: NavParams,public events:Events,public btDataService:BtDataService) {
      }

      ionViewDidLoad() {
        //console.log('ionViewDidLoad DataBkBootstrapPage');
        this.getTodayMatchList();
        this.getHotMatchList();
      }

      //跳转到足球tab页
      goDataIndexPage(){
          this.events.publish('selectRootTab',2,'DataIndexPage');
      }

      //今日赛事
      dyTodayMatch = 3;
      todayMatchList;
      loading;
      getTodayMatchList(){
          this.loading = true;
          this.btDataService.getTodayGroupLeagueMatchList()
              .then(res=>{
                  this.loading = false;
                  if(res.hasOwnProperty('code') && res.code === '1'){
                      this.todayMatchList = res.todayList;
                      return;
                  }
                  console.error("获取今日赛事失败：",res['msg']);
              }).catch(e=>{
                  this.loading = false;
                  console.error("获取今日赛事接口异常：",e);
          });
      }

      //收起和展开赛事列表
      lastDyTodayMatch = this.dyTodayMatch;
      showOrHidden(type){
        if(type == 1){
            this.dyTodayMatch = this.todayMatchList.length;
        }else{
            this.dyTodayMatch = this.lastDyTodayMatch;
        }
      }
      
     //热门赛事列表
     hotMatchList;
     getHotMatchList(){
       this.btDataService.getBkHotLeagueList()
          .then(res=>{
              if(res.hasOwnProperty('code') && res.code == '1'){
                  this.hotMatchList = res.leagueList;
                  return;
              }
              console.error("获取热门赛事失败：",res['msg']);
          }).catch(e=>{
             console.error("获取热门赛事接口异常：",e);
       });
      }

      //联赛首页，leagueId
      goLeaguePage(leagueId){
         this.navCtrl.push('LeagueTabsPage',{leagueId});
      }

}
